﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Principal;

namespace RestNews.Util.Security
{
    /// <summary>
    /// Principal class
    /// </summary>
    public class Principal : IPrincipal
    {
        /// <summary>
        /// The _identity
        /// </summary>
        private UserIdentity _identity;

        /// <summary>
        /// Initializes a new instance of the <see cref="Principal"/> class.
        /// </summary>
        /// <param name="userIdentity">The user identity.</param>
        public Principal(UserIdentity userIdentity)
        {
            _identity = userIdentity;
        }

        /// <summary>
        /// Gets the identity of the current principal.
        /// </summary>
        /// <returns>The <see cref="T:System.Security.Principal.IIdentity" /> object associated with the current principal.</returns>
        public IIdentity Identity
        {
            get { return _identity; }
        }

        /// <summary>
        /// Determines whether the current principal belongs to the specified role.
        /// </summary>
        /// <param name="role">The name of the role for which to check membership.</param>
        /// <returns>
        /// true if the current principal is a member of the specified role; otherwise, false.
        /// </returns>
        public bool IsInRole(string role)
        {
            return _identity.Roles.Contains(role);
        }
    }
}